package install.ren.exercise.test.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author jonny
 * Created on 2021/8/28
 */
@Aspect
//@Component
public class AopAdvice {
    static {
        System.out.println("AopAdvice");
    }
    public AopAdvice(){
        System.out.println("AopAdvice init");
    }

    @Pointcut("execution (* install.ren.exercise.test.controller.*.*(..))")
    public void test() {
    }

    //@Before("test()")
    //public void beforeAdvice() {
    //    System.out.println("beforeAdvice...");
    //}
    //
    //@After("test()")
    //public void afterAdvice() {
    //    System.out.println("afterAdvice...");
    //}

    @Around("test()")
    public Object aroundAdvice(ProceedingJoinPoint proceedingJoinPoint) {
        System.out.println("before");
        try {
            return proceedingJoinPoint.proceed();
        } catch (Throwable t) {
            System.out.println(t);
            t.printStackTrace();
        } finally {
            System.out.println("after");
        }

        return null;
    }

}
